package com.example.demo.com.example.strategy;

import java.util.HashMap;
import java.util.Map;


public class PayStrategy {
    public static final String UNION_PAY = "UnionPay";
    public static final String WECHAT_PAY = "WechatPay";

    //使用注册式单例，将策略放入内存中
    private static Map<String, Payment> paymentMap =  new HashMap<String ,Payment>();

    static{
        paymentMap.put(UNION_PAY,new UnionPay());
        paymentMap.put(WECHAT_PAY,new WechatPay());
    }

    public static Payment get(String payKey){
        if(paymentMap.containsKey(payKey)){
            return paymentMap.get(payKey);
        }else{
            return null;
        }
    }
}
